//
//  InfoPicCollectionViewCell.m
//  CarFace
//
//  Created by dlios on 15-3-28.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "InfoPicCollectionViewCell.h"

@implementation InfoPicCollectionViewCell
- (void)dealloc
{
    [_imageView release];
    [_scrollView release];
    [_picAdress release];
    [super dealloc];
    
}



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.scrollView = [[UIScrollView alloc]init];
        self.scrollView.maximumZoomScale = 2.0;
        self.scrollView.minimumZoomScale = 1.0;
        self.scrollView.delegate = self;
        [self.contentView addSubview:self.scrollView];
        [_scrollView release];
    
        self.imageView = [[UIImageView alloc]init];
        [self.scrollView addSubview:self.imageView];
        [_imageView release];
        
    }
    return self;
}

-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.scrollView.frame = layoutAttributes.bounds;
    self.imageView.frame = self.scrollView.bounds;
    
}

-(void)setPicAdress:(NSString *)picAdress
{
    if (_picAdress != picAdress) {
        [_picAdress release];
        _picAdress = [picAdress retain];
    }
    
    picAdress = [picAdress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:picAdress];
    [self.imageView setImageWithURL:url];
    
    
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.scrollView.zoomScale = 1.0;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return [self.scrollView.subviews firstObject];
}

@end
